package com.hengxinguotong.hxgtwygsp.widget;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;


import com.hengxinguotong.hxgtwygsp.R;

import java.util.List;

/**
 * TODO
 *
 * @author hjz
 * @version V1.0.0
 * @since 2019/2/12 16:56
 */

public abstract class DropListPW<T>
{
    protected Context context;
    protected RecyclerView mRecyclerView;
    protected PopupWindow popupWindow;

    public DropListPW(Context context, int width)
    {
        this.context = context;
        View view = View.inflate(context, R.layout.popup_drop_list, null);
        mRecyclerView = view.findViewById(R.id.mRecyclerView);
        LinearLayoutManager llm = new LinearLayoutManager(context);
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(llm);
        popupWindow = new PopupWindow(view, width, ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置焦点，必须设置，否则PopupWindow内的空间无法响应事件
        popupWindow.setFocusable(true);
        //必须设置，否则获得焦点后页面上其他地方点击无响应
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        //设置点击其他地方 popupWindow消失
        popupWindow.setOutsideTouchable(true);
    }

    public interface OnClickCallback<K>
    {
        void onClickPW(K k);
    }

    public void showAsDropDown(View view)
    {
        popupWindow.showAsDropDown(view, 0, 10);
    }

    public abstract void initData(List<T> list, int index);
}
